package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userOrdersController")
@RequestMapping("/user/order")
@Slf4j
@Api("c端-用户下单")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 用户下单
     *
     * @param ordersSubmitDTO
     * @return
     */
    @ApiOperation("用户下单")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> userOrders(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        //我们需要返回给前端一个实体vo类
        OrderSubmitVO submitVO = ordersService.userOrders(ordersSubmitDTO);
        log.info("前端接收的数据是:{}", submitVO);
        //数据返回给前端
        return Result.success(submitVO);
    }

    /**
     * 查看历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> selectHistory(OrdersPageQueryDTO ordersPageQueryDTO) {
        //返回页数和数据封装的类
        PageResult result = ordersService.selectHistory(ordersPageQueryDTO);
        return Result.success(result);
    }

    /**
     * 查看订单详情
     * @param id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    public Result selectById(@PathVariable Integer id){
        OrderVO orderVO = ordersService.selectById(id);
        return Result.success(orderVO);
    }



    @PutMapping("/cancel/{id}")
    public Result CancelOrders(@PathVariable Integer id){
        //接收前端传来的订单id交给service层去处理,不需要进行返回
        ordersService.updateOrdersStstus(id);
        return Result.success();
    }


    @PostMapping("/repetition/{id}")
    public Result OneMoreOrder(@PathVariable Integer id){
        //获取到前段传来的订单id
        ordersService.OneMoreOrder(id);
        return Result.success();
    }


    /**
     * 完成催单
     */
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        ordersService.reminder(id);
        return Result.success();
    }

}
